#!/usr/bin/env bash
# Usage: nodenv version-file-write <file> <version>

set -e
[ -n "$NODENV_DEBUG" ] && set -x

NODENV_VERSION_FILE="$1"
NODENV_VERSION="$2"

if [ -z "$NODENV_VERSION" ] || [ -z "$NODENV_VERSION_FILE" ]; then
  nodenv-help --usage version-file-write >&2
  exit 1
fi

# Make sure the specified version is installed.
nodenv-prefix "$NODENV_VERSION" >/dev/null

# Write the version out to disk.
echo "$NODENV_VERSION" > "$NODENV_VERSION_FILE"
